<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>会议管理 - 测盟汇系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <style>
        :root {
            --primary-color: #2c5545;
            --primary-hover: #1e4636;
            --text-color: #333;
            --text-light: #555;
            --border-color: #d1d9d6;
            --bg-light: #f5f7f6;
            --bg-page: #e8ecea;
            --white: #fff;
            --shadow: 0 4px 24px rgba(44, 85, 69, 0.1);
            --radius: 12px;
            --transition: all 0.3s ease;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background: var(--bg-page);
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            color: var(--text-color);
            line-height: 1.6;
        }

        .header {
            background: var(--primary-color);
            color: var(--white);
            padding: 1rem 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .logo {
            display: flex;
            align-items: center;
        }

        .logo i {
            font-size: 1.8rem;
            margin-right: 0.8rem;
        }

        .logo h1 {
            font-size: 1.5rem;
            font-weight: 600;
        }

        .user-info {
            display: flex;
            align-items: center;
        }

        .user-info i {
            font-size: 1.2rem;
            margin-right: 0.5rem;
        }

        .logout-btn {
            background: rgba(255, 255, 255, 0.2);
            border: none;
            color: var(--white);
            padding: 0.5rem 1rem;
            border-radius: 4px;
            cursor: pointer;
            transition: var(--transition);
            margin-left: 1rem;
            display: flex;
            align-items: center;
        }

        .logout-btn i {
            margin-right: 0.5rem;
        }

        .logout-btn:hover {
            background: rgba(255, 255, 255, 0.3);
        }

        .container {
            max-width: 1400px;
            margin: 2rem auto;
            padding: 0 2rem;
        }

        .content-card {
            background: var(--white);
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            padding: 2rem;
            margin-bottom: 2rem;
            border: 1px solid var(--border-color);
        }

        .page-title {
            color: var(--primary-color);
            font-size: 1.8rem;
            margin-bottom: 1.5rem;
            display: flex;
            align-items: center;
        }

        .page-title i {
            margin-right: 1rem;
        }

        .action-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 2rem;
        }

        .btn {
            padding: 0.8rem 1.5rem;
            border-radius: var(--radius);
            border: none;
            cursor: pointer;
            font-weight: 500;
            transition: var(--transition);
            display: inline-flex;
            align-items: center;
            text-decoration: none;
        }

        .btn i {
            margin-right: 0.5rem;
        }

        .btn-primary {
            background: var(--primary-color);
            color: var(--white);
        }

        .btn-primary:hover {
            background: var(--primary-hover);
            transform: translateY(-2px);
        }

        .btn-secondary {
            background: var(--bg-light);
            color: var(--text-color);
            border: 1px solid var(--border-color);
        }

        .btn-secondary:hover {
            background: #e1e8e4;
            transform: translateY(-2px);
        }

        .form-control {
            padding: 0.8rem;
            border: 1px solid var(--border-color);
            border-radius: var(--radius);
            font-size: 1rem;
            background: var(--bg-light);
            transition: var(--transition);
        }

        .form-control:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 2px rgba(44, 85, 69, 0.2);
            background: var(--white);
        }

        .status-tag {
            padding: 0.4rem 0.8rem;
            border-radius: 20px;
            font-size: 0.85rem;
            font-weight: 500;
            display: inline-flex;
            align-items: center;
        }

        .status-tag i {
            margin-right: 0.3rem;
            font-size: 0.8rem;
        }

        .status-pending {
            background: #fff3cd;
            color: #856404;
        }

        .status-published {
            background: #d4edda;
            color: #155724;
        }

        .status-rejected {
            background: #f8d7da;
            color: #721c24;
        }

        .action-buttons {
            display: flex;
            gap: 0.5rem;
        }

        .btn-sm {
            padding: 0.5rem 1rem;
            font-size: 0.85rem;
        }

        .pagination {
            display: flex;
            justify-content: center;
            gap: 0.5rem;
            margin-top: 1.5rem;
        }

        .page-item {
            display: inline-flex;
        }

        .page-link {
            padding: 0.6rem 1rem;
            border-radius: var(--radius);
            border: 1px solid var(--border-color);
            color: var(--text-color);
            text-decoration: none;
            transition: var(--transition);
        }

        .page-link:hover {
            background: var(--bg-light);
        }

        .page-item.active .page-link {
            background: var(--primary-color);
            color: var(--white);
            border-color: var(--primary-color);
        }

        .empty-state {
            text-align: center;
            padding: 3rem;
            color: var(--text-light);
        }

        .empty-state i {
            font-size: 3rem;
            margin-bottom: 1rem;
            color: var(--border-color);
        }

        .form-row {
            display: flex;
            flex-wrap: wrap;
            gap: 1rem;
            align-items: center;
        }

        .count-badge {
            background: var(--primary-color);
            color: white;
            padding: 0.25rem 0.75rem;
            border-radius: 20px;
            font-size: 0.9rem;
            font-weight: 500;
        }

        .time-cell {
            font-size: 0.9rem;
            color: var(--text-light);
        }

        .meeting-title {
            font-weight: 600;
            color: var(--primary-color);
        }

        .table {
            width: 100%;
            border-collapse: separate;
            border-spacing: 0;
            margin-bottom: 1.5rem;
        }

        .table thead th {
            background: var(--primary-color);
            color: var(--white);
            padding: 1rem;
            text-align: left;
            font-weight: 500;
        }

        .table tbody tr {
            transition: var(--transition);
        }

        .table tbody tr:hover {
            background: rgba(44, 85, 69, 0.05);
        }

        .table td, .table th {
            padding: 1rem;
            border-bottom: 1px solid var(--border-color);
            vertical-align: middle;
        }

        .search-container {
            display: flex;
            gap: 1rem;
            align-items: center;
            margin-bottom: 1.5rem;
            flex-wrap: wrap;
        }

        .table-responsive {
            overflow-x: auto;
        }

        .no-results {
            text-align: center;
            padding: 3rem;
            color: var(--text-light);
        }

        .no-results i {
            font-size: 3rem;
            margin-bottom: 1rem;
            color: #ccc;
        }

        .pagination-container {
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 1.5rem;
            flex-wrap: wrap;
            gap: 1rem;
        }

        .btn-group {
            display: flex;
            gap: 0.5rem;
        }

        .btn-light {
            background: var(--bg-light);
            color: var(--text-color);
            border: 1px solid var(--border-color);
        }

        .btn-light:hover {
            background: #e1e8e4;
        }

        .disabled {
            opacity: 0.6;
            cursor: not-allowed;
        }

        .disabled:hover {
            transform: none;
            background: var(--primary-color);
        }

        @media (max-width: 768px) {
            .header {
                flex-direction: column;
                text-align: center;
                padding: 1rem;
            }

            .user-info {
                margin-top: 1rem;
            }

            .action-bar {
                flex-direction: column;
                gap: 1rem;
                align-items: flex-start;
            }

            .search-container {
                flex-direction: column;
                align-items: stretch;
            }

            .form-row {
                flex-direction: column;
            }

            .action-buttons {
                flex-wrap: wrap;
            }
        }
    </style>
</head>
<body>
<div class="header">
    <div class="logo">
        <i class="fas fa-store"></i>
        <h1>测盟汇系统</h1>
    </div>
    <div class="user-info">
        <i class="fas fa-user-shield"></i>
        <span>超级管理员：<span th:text="${session.user.username}"></span></span>
        <a th:href="@{/user/logout}" class="logout-btn">
            <i class="fas fa-sign-out-alt"></i>
            退出登录
        </a>
    </div>
</div>

<div class="container">
    <div class="content-card">
        <div class="action-bar">
            <div>
                <a href="/admin/dashboard" class="btn btn-secondary">
                    <i class="fas fa-arrow-left"></i> 返回首页
                </a>
            </div>
            <h2 class="page-title">
                <i class="fas fa-video"></i> 会议管理
            </h2>
            <a href="/admin/meeting/add" class="btn btn-primary">
                <i class="fas fa-plus"></i> 新增会议
            </a>
        </div>

        <div class="search-filter">
            <form th:action="@{/admin/meeting/list}" method="get" class="mb-0">
                <div class="form-row">
                    <!-- 关键词搜索框 -->
                    <div class="col-md-2 col-sm-6 mb-2">
                        <input type="text" id="keyword" class="form-control" name="keyword"
                               placeholder="会议名称或创建人" th:value="${keyword}">
                    </div>
                    <!-- 开始日期时间框 -->
                    <div class="col-md-2 col-sm-6 mb-2">
                        <input type="datetime-local"
                               id="startDate"
                               class="form-control"
                               name="startDate"
                               placeholder="开始时间"
                               th:value="${startDate}"
                               step="1">
                    </div>
                    <!-- 结束日期时间框 -->
                    <div class="col-md-2 col-sm-6 mb-2">
                        <input type="datetime-local"
                               id="endDate"
                               class="form-control"
                               name="endDate"
                               placeholder="结束时间"
                               th:value="${endDate}"
                               step="1">
                    </div>
                    <!-- 审核状态下拉框 -->
                    <div class="col-md-2 col-sm-6 mb-2">
                        <select id="status" class="form-control" name="status">
                            <option value="">全部状态</option>
                            <option value="0" th:selected="${status == '0'}">待审核</option>
                            <option value="1" th:selected="${status == '1'}">已通过</option>
                            <option value="2" th:selected="${status == '2'}">已拒绝</option>
                        </select>
                    </div>
                    <!-- 搜索按钮 -->
                    <div class="col-md-2 col-sm-6 mb-2">
                        <button type="submit" class="btn btn-primary w-100">
                            <i class="fas fa-search"></i> 搜索
                        </button>
                    </div>
                    <!-- 重置按钮 -->
                    <div class="col-md-2 col-sm-6 mb-2">
                        <a th:href="@{/admin/meeting/list}" class="btn btn-secondary w-100">
                            <i class="fas fa-undo-alt"></i> 重置
                        </a>
                    </div>
                </div>
            </form>
        </div>

        <!-- 空状态 -->
        <div th:if="${#lists.isEmpty(meetings)}" class="no-results">
            <i class="fas fa-calendar-times"></i>
            <h4>暂无会议数据</h4>
            <p>点击"新增会议"按钮添加您的第一个会议</p>
            <a th:href="@{/admin/meeting/add}" class="btn btn-primary mt-3">
                <i class="fas fa-plus"></i>添加会议
            </a>
        </div>

        <!-- 会议列表 -->
        <div th:unless="${#lists.isEmpty(meetings)}" class="table-responsive">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>会议名称</th>
                    <th>开始时间</th>
                    <th>结束时间</th>
                    <th>创建人</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="m : ${meetings}">
                    <td th:text="${m.id}"></td>
                    <td>
                        <strong th:text="${m.title}"></strong>
                    </td>
                    <td th:text="${#dates.format(m.startTime, 'yyyy-MM-dd HH:mm')}"></td>
                    <td th:text="${#dates.format(m.endTime, 'yyyy-MM-dd HH:mm')}"></td>
                    <td th:text="${m.creator}"></td>
                    <td>
                        <span th:if="${m.isApproved} == 0" class="status-tag status-pending"><i class="fas fa-hourglass-half"></i>待审核</span>
                        <span th:if="${m.isApproved} == 1" class="status-tag status-published"><i class="fas fa-check"></i>已通过</span>
                        <span th:if="${m.isApproved} == 2" class="status-tag status-rejected"><i class="fas fa-times"></i>已拒绝</span>
                    </td>
                    <td>
                        <div class="action-buttons">
                            <a th:href="@{'/admin/meeting/detail/' + ${m.id}}"
                               class="btn btn-primary btn-sm">
                                <i class="fas fa-eye"></i>详情
                            </a>
                            <a th:href="@{'/admin/meeting/edit/' + ${m.id}}"
                               class="btn btn-secondary btn-sm">
                                <i class="fas fa-edit"></i>编辑
                            </a>
                            <a th:href="@{'/admin/meeting/delete/' + ${m.id}}"
                               class="btn btn-danger btn-sm"
                               onclick="return confirm('确定要删除该会议吗？此操作不可撤销！')">
                                <i class="fas fa-trash-alt"></i>删除
                            </a>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>

        <div class="pagination-container" th:if="${page != null and page.totalPages > 1}">
            <!-- 上一页按钮 -->
            <a th:href="@{/admin/meeting/list(
                keyword=${keyword},
                startDate=${startDate},
                endDate=${endDate},
                status=${status},
                page=${page.number > 0 ? page.number - 1 : 0},
                size=${page.size})}"
               class="btn btn-primary"
               th:classappend="${page.first} ? 'disabled'">
                <i class="fas fa-chevron-left"></i> 上一页
            </a>

            <!-- 页码按钮 -->
            <div class="btn-group">
                <a th:each="i : ${#numbers.sequence(1, page.totalPages)}"
                   th:href="@{/admin/meeting/list(
                    keyword=${keyword},
                    startDate=${startDate},
                    endDate=${endDate},
                    status=${status},
                    page=${i - 1},
                    size=${page.size})}"
                   class="btn"
                   th:class="${i == page.number + 1} ? 'btn-primary' : 'btn-light'"
                   th:text="${i}">
                </a>
            </div>

            <!-- 下一页按钮 -->
            <a th:href="@{/admin/meeting/list(
                keyword=${keyword},
                startDate=${startDate},
                endDate=${endDate},
                status=${status},
                page=${page.number < page.totalPages - 1 ? page.number + 1 : page.totalPages - 1},
                size=${page.size})}"
               class="btn btn-primary"
               th:classappend="${page.last} ? 'disabled'">
                下一页 <i class="fas fa-chevron-right"></i>
            </a>

            <!-- 分页信息 -->
            <div class="align-self-center">
                <span class="text-muted"
                      th:text="'第 ' + (${page.number} + 1) + ' 页，共 ' + ${page.totalPages} + ' 页'"></span>
                <span class="text-muted ml-2"
                      th:text="'总记录数: ' + ${page.totalElements}"></span>
            </div>

            <!-- 每页条数选择 -->
            <div>
                <select class="form-control" onchange="changePageSize(this.value)">
                    <option value="5" th:selected="${page.size} == 5">5条/页</option>
                    <option value="10" th:selected="${page.size} == 10">10条/页</option>
                    <option value="20" th:selected="${page.size} == 20">20条/页</option>
                    <option value="50" th:selected="${page.size} == 50">50条/页</option>
                </select>
            </div>
        </div>
    </div>
</div>

<script>
    // 页面加载后初始化日期选择器
    $(document).ready(function() {
        // 设置日期选择器的初始值（如果有后端传递的值）
        const today = new Date();
        const tomorrow = new Date();
        tomorrow.setDate(today.getDate() + 1);

        // 如果没有后端传递的值，则设置默认值
        if (!$('#startDate').val()) {
            $('#startDate').val(formatDate(today));
        }
        if (!$('#endDate').val()) {
            $('#endDate').val(formatDate(tomorrow));
        }
    });

    function formatDate(date) {
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0');
        const day = String(date.getDate()).padStart(2, '0');
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');

        return `${year}-${month}-${day}T${hours}:${minutes}`;
    };

    function changePageSize(size) {
        const params = new URLSearchParams(window.location.search);
        params.set('size', size);
        params.set('page', 0); // 重置到第一页
        window.location.href = '/admin/meeting/list?' + params.toString();
    }
</script>
</body>
</html>